package com.nuc.iblog.timetask;

import com.nuc.iblog.entity.Article;
import com.nuc.iblog.jpa.ArticleJpa;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class RedisFirstInject implements CommandLineRunner {
    private Logger logger = LoggerFactory.getLogger(RedisFirstInject.class);
    @Autowired
    StringRedisTemplate stringRedisTemplate;
    @Autowired
    ArticleJpa articleJpa;

    @Override
    public void run(String... args) throws Exception {
        List<Article> articles=articleJpa.findAll();
        for(Article article:articles){
            stringRedisTemplate.opsForValue().set(String.valueOf(article.getAid()),String.valueOf(article.getLove()));
        }
    }
}
